/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"B047CAFF-55F7-417E-BAAB-1081134C5EA9",variableType:4}
 */
var fConcepto = null;


/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"CC9DCBA4-4D29-4C8F-8DB8-432684B0C46F"}
 * @AllowToRunInFind
 */
function detalle(event) {
	if (globals.gFechaDesde == null || globals.gFechaHasta == null)
	{
		globals.DIALOGS.showErrorDialog('Error','Por favor, elija un rango de fechas','OK')
		return
	}
	
	if (forms.conceptos_varios_2.controller.find() == false)
	{
		globals.DIALOGS.showErrorDialog('Error','No se pudo iniciar la búsqueda','OK')
		return
	}
	var $fecha = utils.dateFormat(globals.gFechaDesde,'dd-MM-yyyy') + ' ... ' + utils.dateFormat(globals.gFechaHasta,'dd-MM-yyyy')
	forms.conceptos_varios_2.ctacte_pr_varios_to_ctacte_pr.fecha_mov = '#' + $fecha + '|dd-MM-yyyy'
	
	forms.conceptos_varios_2.concepto_id = fConcepto
	
	if (forms.conceptos_varios_2.controller.search() == 0)
	{
		globals.DIALOGS.showWarningDialog('Aviso','No se encontraron resultados','OK')
		return
	}
	forms.conceptos_varios_2.controller.sort('concepto_id asc, ctacte_pr_varios_to_ctacte_pr.fecha_mov asc')
	globals.mostrarForm('conceptos_varios_2')
	
//	var $where = ''
//	/** @type {Array<Object>}*/
/*	var $args = [globals.gFechaDesde, globals.gFechaHasta, globals.gUservID]
	if (fConcepto != null)
	{
		$args.push(fConcepto)
		$where = ' AND concepto_id = ? '
	}
	var $sql = 'SELECT DISTINCT cc.fecha_mov, tb.descripcion as "comprobante", cc.comprob_completo, p.razon_social, p.cuit, cv.concepto_id, conc.descripcion as "concepto", cv.importe '+
					'FROM ctacte_pr_varios "cv" '+
					'INNER JOIN ctacte_pr "cc" ON cc.ctacte_pr_id = cv.ctacte_pr_id '+
					'INNER JOIN conceptos_varios_cc "conc" ON conc.concepto_varios_cc_id = cv.concepto_id '+
					'INNER JOIN tab_mov_pr "tb" ON tb.ctacte_mov_pr_id = cc.cod_mov '+
					'INNER JOIN proveedor "p" ON p.proveedor_id = cc.proveedor_id '+
					'WHERE cc.fecha_mov BETWEEN ? AND ? '+
					'AND cv.userv_id = ? '+
					$where +
					'ORDER BY cv.concepto_id asc, cc.fecha_mov asc, cc.comprob_completo'
	var $ds = databaseManager.getDataSetByQuery('infocom',$sql,$args,-1)
	if ($ds.getMaxRowIndex() == 0)
	{
		globals.DIALOGS.showWarningDialog('Aviso','No se encontraron resultados','OK')
		return
	}
	
	var $params = {
		userv: uservs_to_uservs.razon_social,
		pTitulo: 'Movimientos Desde: ' + utils.dateFormat(globals.gFechaDesde,'dd-MM-yyyy') + ' Hasta: ' + utils.dateFormat(globals.gFechaHasta,'dd-MM-yyyy')
	}
	globals.metodoJasper('impresion','proveedores/conceptos_varios_detalle.jasper','Conceptos_varios_totales',$ds,$params)
*/
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"4B61C4E2-8A55-4701-9FB2-929CF9E7BD19"}
 */
function totales(event) {
	var $where = ''
	/** @type {Array<Object>}*/
	var $args = [globals.gFechaDesde, globals.gFechaHasta, globals.gUservID]
	if (fConcepto != null)
	{
		$args.push(fConcepto)
		$where = ' AND concepto_id = ? '
	}
	var $query = 'SELECT concepto_id, SUM(cv.importe) as "total" FROM ctacte_pr_varios "cv"'+
	' JOIN ctacte_pr "cc" on cc.ctacte_pr_id = cv.ctacte_pr_id ' + 
	' WHERE cc.fecha_mov between ? and ? AND cv.userv_id = ? ' + $where +
	' GROUP BY concepto_id'
	/*var $query = 'SELECT conc.descripcion, SUM(cv.importe) as "total" '+
					'FROM ctacte_pr_varios "cv" '+
					'INNER JOIN ctacte_pr "cc" ON cc.ctacte_pr_id = cv.ctacte_pr_id '+
					'INNER JOIN conceptos_varios_cc "conc" ON conc.concepto_varios_cc_id = cv.concepto_id '+
					'WHERE cc.fecha_mov BETWEEN ? AND ? '+
					'AND cv.userv_id = ? '+
					$where +
					'GROUP BY concepto_id, conc.descripcion '*/
	
	var $ds = databaseManager.getDataSetByQuery('infocom',$query,$args,-1)
	
	if ($ds.getMaxRowIndex() == 0)
	{
		globals.DIALOGS.showWarningDialog('Aviso','No se encontraron resultados','OK')
		return
	}
	
	/*var $params = {
		userv: uservs_to_uservs.razon_social
	}
	globals.metodoJasper('impresion','proveedores/conceptos_varios_totales.jasper','Conceptos_varios_totales',$ds,$params)*/
	var $frm = solutionModel.getForm('conceptos_varios_tot')
	var tipos = [JSColumn.INTEGER, JSColumn.NUMBER]
	$frm.dataSource = $ds.createDataSource('CONCEPTO_VARIOS',tipos)
	
	forms[$frm.name].controller.recreateUI()
	globals.mostrarForm($frm.name)
}
